<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>文件传阅-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background:#fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
	        <!--TAB切换-->
	        <div class="weui_tab" id="tab4">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item" id="">
	                   	 <c:choose><c:when test="${isPrincipal }">未处理</c:when><c:otherwise>未读</c:otherwise></c:choose>（<span id="replyingCount"></span>）
	                </div>
	                <div class="weui_navbar_item" id="auditedTable">
	                     <c:choose><c:when test="${isPrincipal }">已处理</c:when><c:otherwise>已阅</c:otherwise></c:choose>
	                </div>
	            </div>
	            <div class="weui_tab_bd">
			        <div class="weui_panel weui_tab_bd_item mt0" id="replying">
			        	<div id="replyingList">
			        	</div>
			        	<div class="dropload-down">
				        	<div class="loadData dropload-hasData">点击加载更多数据...</div>
				        </div>
			        </div>
			        <div class="weui_panel weui_tab_bd_item mt0" id="replyed">
			       		<div id="replyedList">
			        	</div>
			        	<div class="dropload-down">
				        	<div class="loadData dropload-hasData">点击加载更多数据...</div>
				        </div>
			        </div>
	            </div>
	        </div>
	        <!--EndTAB切换-->
		</div>
	</div>
	
	<script id="replyed-table-template" type="text/x-handlebars-template">
		{{#each rows}}
		<div class="weui_panel_bd">
           <div class="weui_cell">
            	<div class="weui_cell_bd weui_cell_primary">
                	<p>{{sender}}老师</p>
            	</div>
        	</div>
            <div class="weui_media_box weui_media_appmsg">
               <div class="weui_media_bd">
				   <a href="<%=basePath%>/ls/notice/fileAround/detail/{{id}}" style="display:block;">
                      <p class="paragraph f-black f-14 pr10" style="line-height: 25px;">{{content}}</p>
				   </a>
			       <!-- 伸张链接 -->
			       <span class="paragraphExtender f-blue hide">全文</span>
                   <p class="weui_media_desc" style="line-height: 2;">
						{{#if updateTime}}
                   		{{dateFormat updateTime}}
						{{else}}
						{{dateFormat createTime}}
						{{/if}}
					</p>
                   <div class="liketext" style="display:none;"><p class="f-black repay_line"><span class="f-blue">批示：</span>{{guideContent}}</p></div>
				</div>
            </div>
       </div>
	   {{/each}}
	</script>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
	var whf_page = 1, yhf_page = 1, rows = 10;
	var isLoadAudited = false;
	$(function() {
		loadItem(0);
		$('#tab4').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
		$("#auditedTable").click(function() {
			if(!isLoadAudited){
				loadItem(1);
			}
		})
		$(".dropload-hasData").click(function() {
			if($(this).closest(".weui_panel").attr("id") == 'replying') {
				loadItem(0);
			}else {
				loadItem(1);
			}
		})
		
	});
	
	function loadItem(type) {
		var params = {
			page: type == 0 ? whf_page : yhf_page,
  	 		rows: rows,
  	 		type: type
		};	            
       	$.ajax({
          	url : basePath + "/ls/notice/fileAround/page/query",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : params,
            success: function(data){
            	 var id = type == 0 ? "replyingList" : "replyedList";
            	 if(type == 0) $("#replyingCount").html(data.total);
	           	 if(data.rows.length == 0 || params.page*params.rows >= data.total) {// 如果没有数据
	           		$("#" + id).closest(".weui_panel").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	               	if(data.rows.length == 0) return;
	             }
	           	 loadItemHtml(data, id);
	           	 paragraph1();
	           	 type == 0 ? whf_page++ : yhf_page++
            },
            error: function(xhr, type){
                 
            }
          });
	}
	
	function loadItemHtml(data, id){
  		if(data.rows.length > 0) {
  			var myTemplate = Handlebars.compile($("#replyed-table-template").html());
  			Handlebars.registerHelper("equal", function(v1,v2,options) {
  				if(v1 == v2) {
  					//满足添加继续执行
  					return options.fn(this);
  				}else {
  					//不满足条件执行{{else}}部分
  					return options.inverse(this);
  				}
  			});
  			Handlebars.registerHelper("dateFormat", function(v1) {
  				return getTime(v1, "yyyy-MM-dd hh:mm:ss");
  			});
  			$('#' + id).append(myTemplate(data));
  		}
	}
</script>
</html>